package com.huawei.appgallery.forum.section.buoy.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabWidget;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.ArrayList;
import o.bgz;
import o.bqx;
import o.cao;
import o.dey;

public class SegmentTabHost extends TabHost implements OnTabChangeListener {
    private dey ʻ;
    private boolean ʼ;
    private e ʽ;
    private int ˊ;
    private final ArrayList<e> ˋ = new ArrayList();
    private Context ˎ;
    private FrameLayout ˏ;
    private OnTabChangeListener ॱ;
    private cao ᐝ;

    static class b implements TabContentFactory {
        private final Context ˏ;

        public b(Context context) {
            this.ˏ = context;
        }

        public View createTabContent(String str) {
            View view = new View(this.ˏ);
            view.setMinimumWidth(0);
            view.setMinimumHeight(0);
            return view;
        }
    }

    static final class e {
        bgz ˎ;
        @NonNull
        String ˏ;
        int ॱ;

        e(int i, @NonNull String str) {
            this.ॱ = i;
            this.ˏ = str;
        }
    }

    public SegmentTabHost(Context context) {
        super(context);
        ˊ(context, null);
    }

    public SegmentTabHost(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        ˊ(context, attributeSet);
    }

    private void ˊ(Context context, AttributeSet attributeSet) {
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, new int[]{16842995}, 0, 0);
        this.ˊ = obtainStyledAttributes.getResourceId(0, 0);
        obtainStyledAttributes.recycle();
        super.setOnTabChangedListener(this);
    }

    private void ˎ(Context context) {
        if (findViewById(16908307) == null) {
            View linearLayout = new LinearLayout(context);
            linearLayout.setOrientation(1);
            addView(linearLayout, new LayoutParams(-1, -1));
            View tabWidget = new TabWidget(context);
            tabWidget.setId(16908307);
            tabWidget.setOrientation(0);
            linearLayout.addView(tabWidget, new LinearLayout.LayoutParams(-1, -2, 0.0f));
            tabWidget = new FrameLayout(context);
            tabWidget.setId(16908305);
            linearLayout.addView(tabWidget, new LinearLayout.LayoutParams(0, 0, 0.0f));
            tabWidget = new FrameLayout(context);
            this.ˏ = tabWidget;
            this.ˏ.setId(this.ˊ);
            linearLayout.addView(tabWidget, new LinearLayout.LayoutParams(-1, 0, 1.0f));
        }
    }

    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        this.ʼ = true;
    }

    public void setup(Context context, int i, dey o_dey) {
        this.ʻ = o_dey;
        ˎ(context);
        super.setup();
        this.ˎ = context;
        this.ˊ = i;
        ˎ();
        this.ˏ.setId(i);
        if (getId() == -1) {
            setId(16908306);
        }
    }

    private void ˎ() {
        if (this.ˏ == null) {
            this.ˏ = (FrameLayout) findViewById(this.ˊ);
            if (this.ˏ == null) {
                throw new IllegalStateException("No tab content FrameLayout found for id " + this.ˊ);
            }
        }
    }

    public void setOnTabChangedListener(OnTabChangeListener onTabChangeListener) {
        this.ॱ = onTabChangeListener;
    }

    public void ˊ(@NonNull TabSpec tabSpec, int i) {
        tabSpec.setContent(new b(this.ˎ));
        this.ˋ.add(new e(i, tabSpec.getTag()));
        addTab(tabSpec);
    }

    public void onTabChanged(String str) {
        bqx.ˊ("SegmentTabHost", "onTabChanged:" + str);
        if (this.ʼ) {
            ˎ(str);
        }
        if (this.ॱ != null) {
            this.ॱ.onTabChanged(str);
        }
    }

    private void ˎ(@Nullable String str) {
        bgz o_bgz = null;
        bqx.ˊ("SegmentTabHost", "doTabChanged:" + str);
        if (this.ᐝ == null) {
            bqx.ˋ("SegmentTabHost", "doTabChanged, hostAdapter == null");
            return;
        }
        e ˊ = ˊ(str);
        bqx.ˊ("SegmentTabHost", "newTab:" + ˊ);
        if (this.ʽ != ˊ) {
            if (ˊ != null) {
                if (ˊ.ˎ == null) {
                    ˊ.ˎ = this.ᐝ.ˏ(ˊ.ॱ);
                    bqx.ˊ("SegmentTabHost", "newTab.segment:" + ˊ.ˎ);
                    if (this.ʻ == null) {
                        bqx.ˊ("SegmentTabHost", "segmentLauncher == null");
                    } else {
                        bqx.ˊ("SegmentTabHost", "segmentLauncher != null");
                        this.ʻ.ˎ(this.ˊ, ˊ.ˎ, null);
                    }
                }
                cao o_cao = this.ᐝ;
                int i = ˊ.ॱ;
                bgz o_bgz2 = ˊ.ˎ;
                if (this.ʽ != null) {
                    o_bgz = this.ʽ.ˎ;
                }
                o_cao.ˎ(i, o_bgz2, o_bgz);
                if (ˊ.ˎ != null) {
                    ˊ.ˎ.onResume();
                }
                if (!(this.ʽ == null || this.ʽ.ˎ == null)) {
                    this.ʽ.ˎ.onStop();
                }
            }
            this.ʽ = ˊ;
        }
    }

    public void setAdapter(cao o_cao) {
        bqx.ˊ("SegmentTabHost", "setAdapter");
        if (this.ᐝ == null) {
            this.ᐝ = o_cao;
            if (this.ᐝ != null) {
                int ˊ = this.ᐝ.ˊ();
                for (int i = 0; i < ˊ; i++) {
                    TabSpec newTabSpec = newTabSpec(this.ᐝ.ˋ(i));
                    this.ᐝ.ˏ(i, newTabSpec);
                    ˊ(newTabSpec, i);
                    getTabWidget().setDividerDrawable(null);
                }
            }
        }
    }

    @Nullable
    private e ˊ(String str) {
        int size = this.ˋ.size();
        for (int i = 0; i < size; i++) {
            e eVar = (e) this.ˋ.get(i);
            if (eVar.ˏ.equals(str)) {
                return eVar;
            }
        }
        return null;
    }

    public bgz ˏ() {
        if (this.ʽ != null) {
            return this.ʽ.ˎ;
        }
        return null;
    }
}
